<style lang="scss">
/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
@import "uview-plus/index.scss";
*{
	box-sizing: border-box;
}
</style>
<script setup lang="ts">
import autofit from "autofit.js";
import {onLaunch, onShow, onHide, onLoad} from "@dcloudio/uni-app";
import { onMounted } from "vue";
onLoad(()=>{
  getBaiDuToken()
})
onLaunch(() => {
  console.log("App Launch");
  // #ifdef APP-PLUS
  plus.screen.lockOrientation('landscape-primary'); //锁定横屏
  plus.navigator.setFullscreen(true); //隐藏状态栏(应用全屏:只能隐藏状态栏，标题栏和虚拟返回键都还可以显示)
  // #endif
});
onShow(() => {
  console.log("App Show");
});
onHide(() => {
  console.log("App Hide");
});
onMounted(async()=>{
  //#ifdef APP-PLUS
  await requestPermissions();
  //#endif
  // autofit.init({
  //   designHeight: 1080,
  //   designWidth: 1920,
  //   renderDom:"#body",
  //   resize: true
  // })
})
function requestPermissions() {
  return new Promise((resolve, reject) => {
    plus.android.requestPermissions(
        ["android.permission.RECORD_AUDIO"],
        function (e) {
          if (e.deniedAlways.length > 0) {
            console.log("Always Denied!!! " + e.deniedAlways.toString());
            setTimeout(()=>{
              requestPermissions()
            },100)
          }
          if (e.deniedPresent.length > 0) {
            console.log("Present Denied!!! " + e.deniedPresent.toString());
          }
          if (e.granted.length > 0) {
            console.log("Granted!!! " + e.granted.toString());
          }
          resolve(e);
        },
        function (e) {
          console.log("Request Permissions error:" + JSON.stringify(e));
          reject(e);
        }
    );
  });
}
const baiDuKey = {
  appid: "31101339",
  key: "bQzVxn3lvQxotG0bbR2mvo2G",
  secret: "p14P6mxIaVGGLmcAjqVVYjkPddql2nZa",
}
const getBaiDuToken = () => {
  uni.request({
    url: "https://aip.baidubce.com/oauth/2.0/token",
    method: "GET",
    data: {
      grant_type: "client_credentials",
      client_id: baiDuKey.key,
      client_secret: baiDuKey.secret,
    },
    success: (res) => {
      console.log("----获取baidu_token——success");
      // token.value = res.data.access_token
      uni.setStorageSync('baiduToken',res.data.access_token)
      console.log(res.data.access_token)
    },
    fail: () => {
    },
    complete: () => {
    },
  });
}
</script>

